package pe.edu.upc.dsd.esb.whereeat.component.service;

import java.util.List;

import javax.jws.WebService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import pe.edu.upc.dsd.esb.whereeat.component.AbstractComponent;
import pe.edu.upc.dsd.whereeat.domain.Plato;
import pe.edu.upc.dsd.whereeat.service.PlatoService;

@Component
@WebService
public class PlatoServiceComponentImpl extends AbstractComponent implements
		PlatoServiceComponent {

	private Logger logger = Logger.getLogger(PlatoServiceComponentImpl.class);

	@Autowired
	private PlatoService platoService;

	public int guardarPlato(Plato plato) {
		try {
			platoService.save(plato);
			return plato.getCodigo();
		} catch (Exception e) {
			logger.error(e);
		}
		return 0;
	}

	public int actualizarPlato(Plato plato) {
		try {
			platoService.update(plato);
			return 1;
		} catch (Exception e) {
			logger.error(e);
		}
		return 0;
	}

	public int eliminarPlato(Plato plato) {
		try {
			platoService.delete(plato);
			return 1;
		} catch (Exception e) {
			logger.error(e);
		}
		return 0;
	}

	public List<Plato> listarPlatos() {
		try {
			return platoService.findAll();
		} catch (Exception e) {
			logger.error(e);
		}
		return null;
	}

	public List<Plato> obtenerPlatosPorRestaurant(int restaurantId) {
		try {
			return platoService.obtenerPlatosPorRestaurantId(restaurantId);
		} catch (Exception e) {
			logger.error(e);
		}
		return null;
	}

	public Plato obtenerPlatoPorId(int platoId) {
		try {
			return platoService.findById(platoId);
		} catch (Exception e) {
			logger.error(e);
		}
		return null;
	}

}
